<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>区域组织设备终端管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<jsp:include page="../resource.jsp"></jsp:include> 
<style type="text/css">
  .loadingImg {
	background: url('../images/loading1.gif');
	height:60px;
	width:60px;
	background-repeat: no-repeat;
	margin-left:250px;  
    margin-top : 200px;
  }
</style>
<script type="text/javascript">
$(document).ready(function() {
	
	var $el = $('<div></div>').addClass('om-widget-overlay') //蒙版
				.css({
					width: $(window).width(),
					height: $(window).height()
				}).append($('<div></div>').addClass('loadingImg'));
	
      	$('#reordeteTree').omTree({
      		dataSource : 'reOrDeTe!queryAll.do',
            widht : 500,
            onBeforeExpand : function(node){
            	$el.appendTo(document.body);
            	var nodeDom = $("#"+node.nid);
            	if(nodeDom.hasClass("hasChildren") && nodeDom.children("ul").children().length == 0){
            		nodeDom.removeClass("hasChildren");
            		$.ajax({
                        url: 'reOrDeTe!queryAll.do?queryId='+node.id,
                        method: 'POST',
                        dataType: 'json',
                        success: function(data){
                            $("#reordeteTree").omTree("insert", data, node);
                            $el.remove();
                        }
                    });
            	}else{
            		$el.remove();
            	}
            	return true;
            },
            onRightClick : function(nodedata, e){
            	if(nodedata){
	            	$("#reordeteTree").omTree("select", nodedata);
            	}else{
            		return;
            	}
            	//if(nodedata.text.indexOf('终端') == -1){  //终端不显示新增菜单
	            $('#menu').omMenu('show',e);
            	//}
            	e.preventDefault();
            	if(nodedata.id.indexOf('re_') != -1){
            		$('#menu').omMenu('enableItem','addorgItem');
            		$('#menu').omMenu('disableItem','adddevItem');
            		$('#menu').omMenu('disableItem','addTemItem');
            		$('#menu').omMenu('enableItem','addslItem');
            	}else if(nodedata.id.indexOf('or_') != -1){
            		$('#menu').omMenu('disableItem','addorgItem');
            		$('#menu').omMenu('enableItem','adddevItem');
            		$('#menu').omMenu('disableItem','addslItem');
            		$('#menu').omMenu('disableItem','addTemItem');
            	}else if(nodedata.id.indexOf('de_') != -1){
            		$('#menu').omMenu('disableItem','addorgItem');
            		$('#menu').omMenu('disableItem','adddevItem');
            		$('#menu').omMenu('disableItem','addslItem');
            		$('#menu').omMenu('enableItem','addTemItem');
            	}else if(nodedata.id.indexOf('te_') != -1){
            		$('#menu').omMenu('disableItem','addorgItem');
            		$('#menu').omMenu('disableItem','adddevItem');
            		$('#menu').omMenu('disableItem','addslItem');
            		$('#menu').omMenu('disableItem','addTemItem');
            		$('#menu').omMenu('disableItem','addItem');
            	}
            },
            onSelect : function(nodedata){
            	$('#reordeteRoot').parent().removeClass('selected');
            }
      	});
      	
      	$('#reordeteRoot').click(function(){
  		    $(this).parent().addClass('selected');
  		    $('#reordeteTree').find('span.selected').removeClass('selected');
  	  	});
      	
      	$(document.body).bind('click',function(){
      		$("#menu").omMenu("hide");
      	})
      	 $('#menu').omMenu({
         	 contextMenu : true,
             dataSource : [{id:'addItem',label:'新增',icon:'../images/add.png'},
                           {id:'modifyItem',label:'修改',icon:'../images/check.png'},
                           {id:'deleteItem',label:'删除',icon:'../images/delete.png'},
                           {id:'addorgItem',label:'新增组织',icon:'../images/add.png'},
                           {id:'adddevItem',label:'新增设备',icon:'../images/add.png'},
                           {id:'addslItem',label:'新增同级区域',icon:'../images/add.png'},
                           {id:'addTemItem',label:'新增终端',icon:'../images/add.png'}
                          ],
             onSelect : function(item){
             	var selectTreeNode = $("#reordeteTree").omTree('getSelected');
             	if(selectTreeNode == undefined){
              	  $.omMessageBox.alert({content:'请选择父节点！'});
              	  return ;
                }
             	var type = selectTreeNode.id.substring(0,2);
             	var parId = selectTreeNode.id;
             	var nodeId = selectTreeNode.nid;
             	var parName = selectTreeNode.text.substring(0,selectTreeNode.text.indexOf('<'));
             	if(type == 're'){ //处理区域
             		if(item.id == 'deleteItem'){ // 删除
             			if($('#'+nodeId).children('ul').children().length > 0){ //先判断是否已经有子节点，优先过滤，避免每次都发ajax请求
             				$.omMessageBox.alert({content:'区域下面有子节点，不能删除！'});
                        	return ;
             			}
             		    $.ajax({
             		    	url : 'reOrDeTe!queryAll.do?queryId='+parId,
             		    	dataType : 'json',
             		        success : function(data){
             		        	if(data.length > 0){
             		        		$.omMessageBox.alert({content:'区域下面有子节点，不能删除！'});
                                	return ;
             		        	}else{ //删除
             		        		$.omMessageBox.confirm({
             		    	           title:'确认删除',
             		    	           content:'删除请确认！',
             		    	           onClose:function(v){
             		    	               if(v){
             		    	            	  $.ajax({
                       		        			url : 'reOrDeTe!deleteRegions.do',
                       		        			data : {regionsId : parId},
                       		        			success : function(data){
                       		        				if(data == '1'){
                       		        					$.omMessageBox.alert({content:'删除成功！'});
                       		        					$('#reordeteTree').omTree('refresh');
                       		        				}else{
                       		        					$.omMessageTip.show({timeout : 4000,content : '删除失败，该设备已经有相关配置数据，请先清理掉再删除！',type : 'error'});
                       		        					return;
                       		        				}
                       		        			}
                       		        		});
             		    	               }
             		    	           }
             		    	       });
             		        	}
             		        }
             		    });
             		}else if(item.id == 'addItem'){ //新增
             			$('#regionsForm').resetForm();
             			$('#reParentId').parent().parent().show();
             			$('#reParentId').val(parId);
             			//$('#parentName').val(parName);
             			$('#regionsEditor').omDialog('open');
             			$('#regionsEditor').omDialog('open');
             		}else if(item.id == 'modifyItem'){ //修改
             			$('#regionsId').val(parId);
             			$('#reParentId').parent().parent().hide();
             			$.ajax({
             				url : 'reOrDeTe!findRegionsById.do',
             				async : false,
             				data : {regionsId:parId},
             				dataType : 'json',
             				success : function(data){
             					$('#reName').val(data.name);
             					$('#pinYin').val(data.pinYin);
             					$('#abbreviation').val(data.abbreviation);
             					$('#orderNo').val(data.orderNo);
             					$('#enable').val(data.enable);
             					$('#regionsEditor').omDialog('open');
             				}
             			});
             		}else if(item.id == 'addslItem'){ //新增同级区域，父节点设置成和选中的节点相同
             			$('#regionsForm').resetForm();
             			$('#reParentId').parent().parent().show();
             			$.ajax({
             				url : 'reOrDeTe!findRegionsById.do',
             				data : {regionsId:parId},
             				dataType : 'json',
             				success : function(data){
		             			$('#reParentId').val(data.parentId);
             				}
             			});
             			$('#regionsEditor').omDialog('open');
             		}else if(item.id == 'addorgItem'){ //在区域下面新增组织
             			$('#organizationEditor').omDialog('open');
             			$('#organizationForm').resetForm();
             			$('#regionsId_or').val(parId); //设置区域ID
             		}
             	}else if(type == 'or'){ //处理组织
					if(item.id == 'deleteItem'){ // 删除
						if($('#'+nodeId).children('ul').children().length > 0){ //先判断是否已经有子节点，优先过滤，避免每次都发ajax请求
             				$.omMessageBox.alert({content:'组织下面有子节点，不能删除！'});
                        	return ;
             			}
						 $.ajax({
	             		    	url : 'reOrDeTe!queryAll.do?queryId='+parId,
	             		    	dataType : 'json',
	             		        success : function(data){
	             		        	if(data.length > 0){
	             		        		$.omMessageBox.alert({content:'组织下面有子节点，不能删除！'});
	                                	return ;
	             		        	}else{ //删除
	             		        		$.omMessageBox.confirm({
	             		    	           title:'确认删除',
	             		    	           content:'删除请确认！',
	             		    	           onClose:function(v){
	             		    	               if(v){
	             		    	            	  $.ajax({
	                       		        			url : 'reOrDeTe!deleteOrganization.do',
	                       		        			data : {organizationId : parId},
	                       		        			success : function(data){
	                       		        				if(data == '1'){
	                       		        					$.omMessageBox.alert({content:'删除成功！'});
	                       		        					$('#reordeteTree').omTree('remove',selectTreeNode);
	                       		        					//$('#reordeteTree').omTree('refresh');
	                       		        				}else{
	                       		        					$.omMessageTip.show({timeout : 4000,content : '删除失败，该设备已经有相关配置数据，请先清理掉再删除！',type : 'error'});
	                       		        					return;
	                       		        				}
	                       		        			}
	                       		        		});
	             		    	               }
	             		    	           }
	             		    	       });
	             		        	}
	             		        }
	             		    });
             		}else if(item.id == 'addItem'){ //新增
             			$('#organizationEditor').omDialog('open');
             		    $('#organizationForm').resetForm();
             		    $('#orParentId').val(parId); //设置上级组织id
             		}else if(item.id == 'modifyItem'){ //修改
             			$('#organizationEditor').omDialog('open');
             			$('#organizationForm').resetForm();
             		    $('#organizationId').val(parId); //设置组织ID
             		    $.ajax({
             		    	url : 'reOrDeTe!findOrganizationById.do',
             		    	data : {organizationId : parId},
             		    	dataType : 'json',
             		    	success : function(data){
             		    		$('#orName').val(data.name);
             		    		$('#type').val(data.type);
             		    		$('#orenable').val(data.enable);
             		    	}
             		    });
             		}else if(item.id == 'adddevItem'){
             			$('#deviceEditor').omDialog('open');
             			$('#deviceForm').resetForm();
             			$('#de_organizationId').val(parId); //设置设备的关联组织
             		}
             	}else if(type == 'de'){ //处理设备
					if(item.id == 'deleteItem'){ // 删除
						if($('#'+nodeId).children('ul').children().length > 0){ //先判断是否已经有子节点，优先过滤，避免每次都发ajax请求
             				$.omMessageBox.alert({content:'设备下面有子节点，不能删除！'});
                        	return ;
             			}
						 $.ajax({
	             		    	url : 'reOrDeTe!queryAll.do?queryId='+parId,
	             		    	dataType : 'json',
	             		        success : function(data){
	             		        	if(data.length > 0){
	             		        		$.omMessageBox.alert({content:'设备下面有子节点，不能删除！'});
	                                	return ;
	             		        	}else{ //删除
	             		        		$.omMessageBox.confirm({
	             		    	           title:'确认删除',
	             		    	           content:'删除请确认！',
	             		    	           onClose:function(v){
	             		    	               if(v){
	             		    	            	  $.ajax({
	                       		        			url : 'reOrDeTe!deleteDevice.do',
	                       		        			data : {guid : parId},
	                       		        			success : function(data){
	                       		        				if(data == '1'){
	                       		        					$.omMessageBox.alert({content:'删除成功！'});
	                       		        					$('#reordeteTree').omTree('remove',selectTreeNode);
	                       		        				}else{
	                       		        					$.omMessageTip.show({timeout : 4000,content : '删除失败，该设备已经有相关配置数据，请先清理掉再删除！',type : 'error'});
	                       		        					return;
	                       		        				}
	                       		        			}
	                       		        		});
	             		    	               }
	             		    	           }
	             		    	       });
	             		        	}
	             		        }
	             		    });
             		}else if(item.id == 'addItem'){ //新增
             			$('#deviceEditor').omDialog('open');
             			$('#deviceForm').resetForm();
             			$('#parentDeviceId').val(parId); //设置设备的父设备
             		}else if(item.id == 'modifyItem'){ //修改
             			$('#deviceForm').resetForm();
             			$('#deviceId').val(parId); //设置设备ID
             			$.ajax({
             		    	url : 'reOrDeTe!findDeviceById.do',
             		    	data : {deviceId : parId},
             		    	dataType : 'json',
             		    	success : function(data){
             		    		$('#deviceId').val(data.guid);
             		    		$('#hdType').omCombo('value',data.hdType.id.toString());
             		    		$('#params').omCombo('value',data.params.id.toString());
             		    		$('#hdTypeId').val(data.hdType.id);
             		    		$('#paramsId').val(data.params.id);
             		    		$('#domain').val(data.domain);
             		    		$('#dename').val(data.name);
             		    		$('#maintainStatus').val(data.maintainStatus);
             		    		$('#rooter').val(data.rooter);
             		    		$('#deviceEditor').omDialog('open');
             		    	}
             		    });
             		}else if(item.id == 'addTemItem'){ //新增终端
             			$('#terminalEditor').omDialog('open');
             			$('#terminalForm').resetForm();
             			$('#te_deviceId').val(parId); //设置设备id
             		}
             	}else if(type == 'te'){ //处理终端
					if(item.id == 'deleteItem'){ // 删除
						$.omMessageBox.confirm({
  		    	           title:'确认删除',
  		    	           content:'删除请确认！',
  		    	           onClose:function(v){
  		    	               if(v){
  		    	            	  $.ajax({
            		        			url : 'reOrDeTe!deleteTerminal.do',
            		        			data : {terminalguid : parId},
            		        			success : function(data){
            		        				if(data == '1'){
            		        					$.omMessageBox.alert({content:'删除成功！'});
            		        					$('#reordeteTree').omTree('remove',selectTreeNode);
            		        				}else{
            		        					$.omMessageTip.show({timeout : 4000,content : '删除失败，该设备已经有相关配置数据，请先清理掉再删除！',type : 'error'});
            		        					return;
            		        				}
            		        			}
            		        		});
  		    	               }
  		    	           }
  		    	       });
             		}else if(item.id == 'modifyItem'){ //修改
             			$('#terminalForm').resetForm();
             			$('#terminalId').val(parId); //设置设备id
             			$.ajax({
             		    	url : 'reOrDeTe!findTerminalById.do',
             		    	data : {terminalId : parId},
             		    	dataType : 'json',
             		    	success : function(data){
             		    		$('#hdType_1').omCombo('value',data.hdType.id.toString());
             		    		$('#params_1').omCombo('value',data.params.id.toString());
             		    		$('#hdTypeId_1').val(data.hdType.id);
             		    		$('#paramsId_1').val(data.params.id);
             		    		$('#tedomain').val(data.domain);
             		    		$('#tename').val(data.name);
             		    		$('#channelNo').val(data.channelNo);
             		    		$('#temaintainStatus').val(data.maintainStatus.toString());
             		    		$('#terminalEditor').omDialog('open');
             		    	}
             		    });
             		}
             	}
             }
         });
      	
      	 $('#regions').omCombo({
             dataSource : 'reOrDeTe!findRegions.do',
             onValueChange : function(target, newValue, oldValue) {
                 getOrganizationRecords();
             }
         });
      	$('#regions').bind('change',function(){
      	    if($('#regions').val() == ''){
      	    	$('#regions').omCombo('value','');
      	    }
      	})
      	 
      	 $('#organization').omCombo({
             dataSource : 'reOrDeTe!findOrganizations.do',
             onValueChange : function(target, newValue, oldValue) {
                 getDevice();
                 if($('#organization').val() == ''){
                	 $('#organization').omCombo('value','');
                 }
             }
         });
      	$('#organization').bind('change',function(){
      	    if($('#organization').val() == ''){
      	    	$('#organization').omCombo('value','');
      	    }
      	})
      	 $('#device').omCombo({
             dataSource : 'reOrDeTe!findDevices.do',
             onValueChange : function(target, newValue, oldValue) {
                 getDevice();
             }
         });
      	$('#device').bind('change',function(){
      	    if($('#device').val() == ''){
      	    	$('#device').omCombo('value','');
      	    }
      	})
      	 function getOrganizationRecords(){
      		var regions = $('#regions').omCombo('value');
            $.ajax({
            	url : 'reOrDeTe!findOrganizations.do',
                data : {regionsId : regions},
                dataType : 'json',
                async : false,
                success : function(data){
                	$('#organization').val('').omCombo('setData', data);
                	$('#device').val('').omCombo( 'setData', []);
                	$('#organization').omCombo('value','');
                	$('#device').omCombo('value','');
                }
            });
      	 }
      	 
      	 function getDevice(){
      		var organization = $('#organization').omCombo('value');
            $.ajax({
            	url : 'reOrDeTe!findDevices.do',
                data : {organizationId : organization},
                dataType : 'json',
                async : false,
                success : function(data){
                	$('#device').val('').omCombo('setData', data);
                }
            });
      	 }
      	 
      	 $('#serachTree').click(function(){
      		$el.appendTo(document.body);
      		var regions = $('#regions').omCombo('value');
      		var organization = $('#organization').omCombo('value');
      		var device = $('#device').omCombo('value');
      		if(device){
      			queryTreeData('de_'+device);
      		}else if(organization){
      			queryTreeData('or_'+organization);
      		}else if(regions){
      			queryTreeData('re_'+regions);
      		}else{
      			queryTreeData(null);
      		}
      	 });
      	 
      	 function queryTreeData(id){
      		$('#reordeteTree').omTree('setData' , 'reOrDeTe!queryAll.do?queryId='+id);
			$('#reordeteTree').omTree('refresh');
			$el.remove();
      	 }
      	 
      	 /*******************弹出窗口********************************************/
      	 $('#regionsEditor').omDialog({
      		  autoOpen: false,
	  		  height: 260,
	  		  width : 480,
		  	  buttons: [{
	                text : "保存", 
	                click : function () {
	                	$('#regionsForm').submit();
	                }
	            }, {
	                text : "取消", 
	                click : function () {
	                    $("#regionsEditor" ).omDialog("close");
	                }
	            }]

      	 });
      	 
      	 $('#organizationEditor').omDialog({
      		  autoOpen: false,
	  		  height: 200,
	  		  width : 480,
		  	  buttons: [{
	                text : "保存", 
	                click : function () {
	                	$('#organizationForm').submit();
	                }
	            }, {
	                text : "取消", 
	                click : function () {
	                    $("#organizationEditor" ).omDialog("close");
	                }
	            }]
      	 });
      	 $('#deviceEditor').omDialog({
      		  autoOpen: false,
	  		  height: 300,
	  		  width : 480,
		  	  buttons: [{
	                text : "保存", 
	                click : function () {
	                	$('#deviceForm').submit();
	                }
	            }, {
	                text : "取消", 
	                click : function () {
	                    $("#deviceEditor" ).omDialog("close");
	                }
	            }]
      	 });
      	 $('#terminalEditor').omDialog({
      		  autoOpen: false,
	  		  height: 300,
	  		  width : 480,
		  	  buttons: [{
	                text : "保存", 
	                click : function () {
	                	$('#terminalForm').submit();
	                }
	            }, {
	                text : "取消", 
	                click : function () {
	                    $("#terminalEditor" ).omDialog("close");
	                }
	            }]
      	 });
      	/************************************提交表单*********************/
      	var options  = {
      		  url : 'reOrDeTe!saveRegions.do',
                success : function(data){
                   	if(data != '0'){
                       	$('#regionsEditor').omDialog('close');
                       	$('#reordeteTree').omTree('refresh');
                       	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                   	}else{
                   		$.omMessageTip.show({timeout : 4000,content : '保存失败！',type : 'error'});
                   	}
                }
      	  };
      	$('#regionsForm').submit(function() {
                $(this).omAjaxSubmit(options);
                return false;//返回false,阻止浏览器默认行为
            });
      	
      	var options_or  = {
        		  url : 'reOrDeTe!saveOrganization.do',
                  success : function(data){
                     	if(data != '0'){
                         	$('#organizationEditor').omDialog('close');
                         	$('#reordeteTree').omTree('refresh');
                         	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                     	}else{
                     		$.omMessageTip.show({timeout : 4000,content : '保存失败！',type : 'error'});
                     	}
                  }
        	  };
        	$('#organizationForm').submit(function() {
                  $(this).omAjaxSubmit(options_or);
                  return false;//返回false,阻止浏览器默认行为
              });
         var options_de  = {
          		  url : 'reOrDeTe!saveDevice.do',
                    success : function(data){
                       	if(data != '0'){
                           	$('#deviceEditor').omDialog('close');
                           	$('#reordeteTree').omTree('refresh');
                           	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                       	}else{
                       		$.omMessageTip.show({timeout : 4000,content : '保存失败！',type : 'error'});
                       	}
                    }
          	  };
          	$('#deviceForm').submit(function() {
                    $(this).omAjaxSubmit(options_de);
                    return false;//返回false,阻止浏览器默认行为
            });
          	
         var options_te  = {
          		  url : 'reOrDeTe!saveTerminal.do',
                  success : function(data){
                     	if(data != '0'){
                         	$('#terminalEditor').omDialog('close');
                         	$('#reordeteTree').omTree('refresh');
                         	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                     	}else{
                     		$.omMessageTip.show({timeout : 4000,content : '保存失败！',type : 'error'});
                     	}
                  }
          	  };
          	$('#terminalForm').submit(function() {
                    $(this).omAjaxSubmit(options_te);
                    return false;//返回false,阻止浏览器默认行为
            });
          	
          	$('#channelNo').omNumberField({allowDecimals:false,allowNegative:false});
        	
        /****************表单提交*********************************************/
         $('#hdType').omCombo({
        	 dataSource : 'reOrDeTe!findHdType.do',
        	 onValueChange : function(target, newValue, oldValue){
        		 $('#hdTypeId').val(newValue);
        	 }
         });
         $('#params').omCombo({
        	 dataSource : 'reOrDeTe!findParams.do',
        	 onValueChange : function(target, newValue, oldValue){
        		 $('#paramsId').val(newValue);
        	 }
         });
         $('#hdType_1').omCombo({
        	 dataSource : 'reOrDeTe!findHdType.do',
        	 onValueChange : function(target, newValue, oldValue){
        		 $('#hdTypeId_1').val(newValue);
        	 }
         });
         $('#params_1').omCombo({
        	 dataSource : 'reOrDeTe!findParams.do',
        	 onValueChange : function(target, newValue, oldValue){
        		 $('#paramsId_1').val(newValue);
        	 }
         });

         //选择未入网设备列表
         $("#deviceListDialog").omDialog({
 		    autoOpen: false,
 		    height: 400,
 		    width : 700,
 		    modal: true,
 		    buttons: [{
 	        text : "确定", 
 	        click : function () {
 	        	var selects = $("#deviceList").omGrid("getSelections",true);
 	        	$('#deviceId').val(selects[0].guid);
		    	$('#hdType').omCombo('value',selects[0].hdType.id.toString());
		    	$('#params').omCombo('value',selects[0].params.id.toString());
		    	$('#hdTypeId').val(selects[0].hdType.id);
		    	$('#paramsId').val(selects[0].params.id);
		    	$('#domain').val(selects[0].domain);
		    	$('#dename').val(selects[0].name);
		    	$('#maintainStatus').val(selects[0].maintainStatus);
		    	$('#rooter').val(selects[0].rooter);
	 	        $("#deviceListDialog" ).omDialog("close");
 	        }
 	     }, {
 	        text : "取消", 
 	        click : function () {
 	          $("#deviceListDialog" ).omDialog("close");
 	      }
 	  	}]
	 	});
         $('#queryDevice').click(function(){
	 			 $('#deviceList').omGrid({
	 		        	dataSource : 'reOrDeTe!findNoInNetDevice.do',
	 		            height : '280',
	 		            limit : 10,
	 		            showIndex : true,
	 		            colModel : [ 
	 		                         {header : '出厂编号', name : 'serial', width : 140, align : 'center'},
	 		                         {header : 'GUID', name : 'guid', width : 275, align : 'center' },
	 		                         {header : '名称', name : 'name', width : 140, align : 'center'},
	 		                         ]
	 		        });
	 		 
	 		 $("#deviceListDialog").omDialog('open');
	 		 return false;
	 	 });
         
         $("#serialQuery").click(function(){
        	 var serial = $("#deviceSerialS").val();
        	 $('#deviceList').omGrid('setData','reOrDeTe!findNoInNetDevice.do?serial='+serial);
        	 return false;
         });
         
       //选择学校列表
         $("#schoolListDialog").omDialog({
 		    autoOpen: false,
 		    height: 400,
 		    width : 450,
 		    modal: true,
 		    buttons: [{
 	        text : "确定", 
 	        click : function () {
 	        	var selects = $("#schoolList").omGrid("getSelections",true);
 	        	$('#orName').val(selects[0].name);
 	        	$("#schoolId").val(selects[0].id);
	 	        $("#schoolListDialog" ).omDialog("close");
 	        }
 	     }, {
 	        text : "取消", 
 	        click : function () {
 	          $("#schoolListDialog" ).omDialog("close");
 	      }
 	  	}]
	 	});
         $('#querySchool').click(function(){
	 			 $('#schoolList').omGrid({
	 		        	dataSource : 'reOrDeTe!findSchoolData.do',
	 		            height : '280',
	 		            limit : 10,
	 		            showIndex : true,
	 		            colModel : [ 
	 		                         {header : 'ID', name : 'id', width : 90, align : 'center'},
	 		                         {header : '名称', name : 'name', width : 140, align : 'center' },
	 		                         {header : '区域代码', name : 'regionalCode', width : 90, align : 'center'},
	 		                         ]
	 		        });
	 		 
	 		 $("#schoolListDialog").omDialog('open');
	 		 return false;
	 	 });
         
         $("#schoolQuery").click(function(){
        	 var name = encodeURIComponent($("#schoolName").val());
        	 name = encodeURIComponent(name);
        	 $('#schoolList').omGrid('setData','reOrDeTe!findSchoolData.do?schoolName='+name);
        	 return false;
         });
});

</script>   
  </head>
  
  <body>
  <div class="select_table">


<table   cellpadding="0" cellspacing="0" class="layout"  >

          <tr>
            <td width="5%" align="right">区域：</td>
            <td width="12%">
              <input name="regions" id="regions" type="text"/>
            </td>
            <td width="5%" align="right">组织：</td>
            <td width="12%">
              <input name="organization" id="organization" type="text"/>
            </td>
            <td width="5%" align="right">设备：</td>
            <td width="12%">
              <input name="device" id="device" type="text"/>
            </td>
            <td>
            <td align="left">
            <button class="button_u" id="serachTree" onmousemove="this.className='button_f'" onmousedown="this.className='button_d'" onmouseout="this.className='button_u'">查询</button></td>
          </tr>
          </table>
</div>
    <div class="toolbar mar"></div>
	<div class="catalogTree">
         <ul class="om-tree om-widget">
		     <li class="om-tree-node collapsable"  id="reordeteRootli">
		        <div class="hitarea om-tree-node-hitarea -hitarea collapsable-hitarea"></div>
		        <span class="folder selected"><a href="#"  id="reordeteRoot">设备菜单</a></span>
		        <ul id="reordeteTree"></ul>
		     </li>
		  </ul>
     <div id="menu"></div>
	</div>
	
	<div id="regionsEditor" title="编辑区域" style="display: none;">
     <form id="regionsForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="10%" align="right">区域名称：</td>
               <td width="28%" colspan="3">
                   <input type="text" name="regionsId" id="regionsId" style="display: none;"/>
                   <input type="text" name="reParentId" id="reParentId" style="display: none;"/>
                   <input type="text" id="reName" name="re.name" class="input_text" />
               </td>
             </tr>
             <tr>
               <td align="right">区域拼音：</td>
               <td colspan="3"><input type="text" name="re.pinYin" id="pinYin" class="input_text"  /></td>
             </tr>
             <tr>
               <td align="right">拼音简写：</td>
               <td colspan="3"><input type="text" name="re.abbreviation" id="abbreviation"  class="input_text"  /></td>
             </tr>
             <tr>
               <td align="right">排序：</td>
               <td colspan="3"><input type="text"  class="input_text" name="re.orderNo" id="orderNo"  /></td>
             </tr>
             <tr>
               <td align="right">是否启用：</td>
               <td colspan="3">
               <select name="re.enable" id="enable" class="input_slelct">
                  <option value="1">是</option>
                  <option value="0">否</option>
               </select>
             </tr>
           </table>
         </form>
   </div>
   
   <div id="organizationEditor" title="编辑组织" style="display: none;">
     <form id="organizationForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="10%" align="right">组织名称：</td>
               <td width="28%" colspan="3">
                   <input type="text" name="organizationId" id="organizationId" style="display: none;"/>
                   <input type="text" name="orParentId" id="orParentId" style="display: none;"/>
                   <input type="text" name="regionsId_or" id="regionsId_or" style="display: none;"/>
                   <input type="text" name="orgni.schoolId" id="schoolId" style="display: none;"/>
                   <input type="text" id="orName" name="orgni.name" class="input_text" />
                   <button class="button_u" id="querySchool" onmousemove="this.className='button_f'" onmousedown="this.className='button_d'" onmouseout="this.className='button_u'">选择学校</button>
               </td>
             </tr>
             <tr>
               <td align="right">类型：</td>
               <td colspan="3">
                  <select name="orgni.type" id="type" class="input_slelct">
	                  <option value="1">运维机构</option>
	                  <option value="2">教育局</option>
	                  <option value="4">学校</option>
                  </select>
               </td>
             </tr>
             <tr>
               <td align="right">是否启用：</td>
               <td colspan="3">
               <select name="orgni.enable" id="orenable" class="input_slelct">
                  <option value="1">是</option>
                  <option value="0">否</option>
               </select>
             </tr>
           </table>
         </form>
   </div>
   
   <div id="deviceEditor" title="编辑设备" style="display: none;">
     <form id="deviceForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
          	<tr>
               <td width="10%" align="right">GUID：</td>
               <td width="28%" colspan="3">
                   <input type="text" name="deviceId" id="deviceId" class="input_text" readonly="readonly"/>
                   <button class="button_u" id="queryDevice" onmousemove="this.className='button_f'" onmousedown="this.className='button_d'" onmouseout="this.className='button_u'">选择</button>
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">设备名称：</td>
               <td width="28%" colspan="3">
                   <input type="text" name="parentDeviceId" id="parentDeviceId" value="" style="display: none;"/>
                   <input type="text" name="de_organizationId" id="de_organizationId" style="display: none;"/>
                   <input type="text" id="dename" name="de.name" class="input_text" />
               </td>
             </tr>
             <tr>
               <td align="right">硬件类型编号：</td>
               <td colspan="3">
                  <input name="hdTypeName" id="hdType"/>
                  <input name="hdTypeId" id="hdTypeId" style="display: none;"/>
               </td>
             </tr>
             <tr>
               <td align="right">设备表序号：</td>
               <td colspan="3">
                  <input name="paramsName" id="params"/>
                  <input name="paramsId" id="paramsId" style="display: none;"/>
               </td>
             </tr>
             <tr>
               <td align="right">域名：</td>
               <td colspan="3">
                  <input name="de.domain" id="domain" class="input_text" />
               </td>
             </tr>
             <tr>
               <td align="right">维护状态：</td>
               <td colspan="3">
                  <select name="de.maintainStatus" id="maintainStatus" class="input_slelct">
	                  <option value="0">未授权</option>
	                  <option value="1">已授权</option>
	                  <option value="2">待检</option>
	                  <option value="3">检查中</option>
	                  <option value="4">待修</option>
	                  <option value="5">维修中</option>
	                  <option value="6">已封存</option>
	                  <option value="7">解除封存</option>
	                  <option value="8">待用</option>
	               </select>
               </td>
             </tr>
             <tr>
               <td align="right">节点标志：</td>
               <td colspan="3">
               <select name="de.rooter" id="rooter" class="input_slelct">
                  <option value="1">平台服务器</option>
                  <option value="0">下级平台服务器/前置主机</option>
               </select>
             </tr>
           </table>
         </form>
   </div>
   
    <div id="terminalEditor" title="编辑终端" style="display: none;">
     <form id="terminalForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="10%" align="right">终端名称：</td>
               <td width="28%" colspan="3">
                   <input type="text" name="terminalId" id="terminalId" style="display: none;"/>
                   <input type="text" name="te_deviceId" id="te_deviceId" style="display: none;"/>
                   <input type="text" id="tename" name="te.name" class="input_text" />
               </td>
             </tr>
             <tr>
               <td align="right">硬件类型编号：</td>
               <td colspan="3">
                  <input name="hdTypeName_1" id="hdType_1"/>
                  <input name="hdTypeId_1" id="hdTypeId_1" style="display: none;"/>
               </td>
             </tr>
             <tr>
               <td align="right">设备表序号：</td>
               <td colspan="3">
                  <input name="paramsName_1" id="params_1"/>
                  <input name="paramsId_1" id="paramsId_1" style="display: none;"/>
               </td>
             </tr>
             <tr>
               <td align="right">域名：</td>
               <td colspan="3">
                  <input name="te.domain" id="tedomain" class="input_text" />
               </td>
             </tr>
             <tr>
               <td align="right">通道编号：</td>
               <td colspan="3">
                  <input name="te.channelNo" id="channelNo" class="input_text" />
               </td>
             </tr>
             <tr>
               <td align="right">维修状态：</td>
               <td colspan="3">
	               <select name="te.maintainStatus" id="temaintainStatus" class="input_slelct">
	                  <option value="0">未授权</option>
	                  <option value="1">已授权</option>
	                  <option value="2">待检</option>
	                  <option value="3">检查中</option>
	                  <option value="4">待修</option>
	                  <option value="5">维修中</option>
	                  <option value="6">已封存</option>
	                  <option value="7">解除封存</option>
	                  <option value="8">待用</option>
	               </select>
               </td>
             </tr>
           </table>
         </form>
   </div>
   <div id="deviceListDialog" title="选择设备" style="display: none;">
   		<div class="select_table">
		<table   cellpadding="0" cellspacing="0" class="layout"  border="0">
	          <tr>
	            <td width="11%" align="right">出厂编号：</td>
	            <td width="9%">
	            	<input name="deviceSerial" id="deviceSerialS" type="text"/>
	            </td>
	            <td align="left">
	            	<button class="button_u" id="serialQuery" onmousemove="this.className='button_f'" onmousedown="this.className='button_d'" onmouseout="this.className='button_u'">查询</button>
	            </td>
	          </tr>
	    </table>
	</div>
      <table id="deviceList"></table>
   </div>
   
   <div id="schoolListDialog" title="选择学校" style="display: none;">
   		<div class="select_table">
		<table   cellpadding="0" cellspacing="0" class="layout"  border="0">
	          <tr>
	            <td width="11%" align="right">名称：</td>
	            <td width="9%">
	            	<input name="schoolName" id="schoolName" type="text"/>
	            </td>
	            <td align="left">
	            	<button class="button_u" id="schoolQuery" onmousemove="this.className='button_f'" onmousedown="this.className='button_d'" onmouseout="this.className='button_u'">查询</button>
	            </td>
	          </tr>
	    </table>
	</div>
      <table id="schoolList"></table>
   </div>
  </body>
</html>
